<?php
/**
 * Created by Wyp.
 * User: pc
 * Date: 2019/11/27
 * Time: 15:41
 */
namespace App\Modules\Live\Services;

class PushUrl
{
    /**
     * 获取推流地址
     * 如果不传key和过期时间，将返回不含防盗链的url
     * @param domain 您用来推流的域名
     * @param streamName 您用来区别不同推流地址的唯一流名称
     * @param key 安全密钥
     * @param time 过期时间 sample 2016-11-12 12:00:00
     * @return String url
     */
    function getPushUrl($domain, $streamName, $key = null, $time = null){
        if($key && $time){
            $txTime = strtoupper(base_convert(strtotime($time),10,16));
            //txSecret = MD5( KEY + streamName + txTime )
            $txSecret = md5($key.$streamName.$txTime);
            $ext_str = "?".http_build_query(array(
                    "txSecret"=> $txSecret,
                    "txTime"=> $txTime
                ));
        }
        return "rtmp://".$domain."/live/".$streamName . (isset($ext_str) ? $ext_str : "");
    }
}


//echo getPushUrl("123.test.com","123456","69e0daf7234b01f257a7adb9f807ae9f","2016-09-11 20:08:07");


